<?php
require 'database.php';
$id = $_GET["quId"];
$sql = "SELECT q.Id, q.Subject, q.Description,q.UserId,
		CONCAT(CONCAT(u.fname, ' '), u.lname)  as 'userName',
		DAY(q.creationTime) as 'day',
		MONTHNAME(q.creationTime) as 'Month', 
		YEAR(q.creationTime) as 'year', 
		u.ImgPath
		FROM question q 
		INNER JOIN forumuser u ON q.userId = u.Id
		WHERE q.IsActive = 1 
		AND q.id=".$id;
$result = mysql_query($sql);
?>


<div class="question">
<?php
	$recordSet = mysql_fetch_array($result);
	$subject = $recordSet["Subject"];
	$creationTime = $recordSet["creationTime"];
	$UserId = $recordSet["userName"];
	$desc =  $recordSet["Description"];
	$day =  $recordSet["day"];
	$month =  $recordSet["Month"];
	$year  =  $recordSet["year"];
	$imgPath = $recordSet["ImgPath"];
	echo "<h3>$subject</h3><hr />";
	echo $desc."<br/><br/>";
	echo "<b>Created By : </b>$UserId<br />";
	echo "<b>Created at : </b>$day $month $year";
	echo "<img src='".$imgPath."' width='50px' height='50px' /> ";
?>
</div>
<hr/>
<b>Answers:</b>
<?php
$sql = "SELECT a.Answer,a.ByUserId, 
		CONCAT(CONCAT(CONCAT(CONCAT(DAY(a.CreationTime ),' '),
		MONTHNAME(a.CreationTime)),' '),YEAR(a.CreationTime)) 
		as 'creationTime',
		CONCAT(CONCAT(u.fname, ' '),u.lname) as userName,
		u.ImgPath
		 FROM answer a 
		INNER JOIN forumuser u ON u.Id = a.ByUserId
		WHERE a.questionId =".$id;
$result = mysql_query($sql);
while($recordSet = mysql_fetch_array($result))
{
	$answer = $recordSet['Answer'];
	echo '<div class="question">'.$answer;
	echo '<br /><b>By : '.$recordSet['userName'].'</b>';
	echo '<br /><b>Date : </b>'.$recordSet['creationTime'].' </br>';
	echo "<img src='".$recordSet['ImgPath']."' width='50px' height='50px' /> ";
	echo '<hr /></div>';

}	
?>

<form method="post" action="addAnswer.php">
<input type="hidden" name="queId" value="<?php echo $_GET["quId"]; ?>" />
<table>
<tr>
<td> Answer</td>
<td>
<textarea  class="required" cols="50" rows="7" name="txtAnswer">
			</textarea>

</td>
</tr>
<tr>
		<td colspan="2" align="right"> <input type="submit" /></td>
	</tr>
</table>
</form>